package game;

import game.Player.Input;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;

import java.awt.*;

public class MenuButton {

    protected double x, y, w, h;
    protected String labelText, clickReturn;
    protected ButtonType buttonType;
    protected Color defaultColor, hoverColor;

    public enum ButtonType{
        LabelButton
    }

    public MenuButton(double x, double y, Color defaultColor, Color hoverColor, String labelText, String clickReturn){
        this.x = x; this.y = y;
        Text auxText = new Text(labelText);
        this.w = auxText.getLayoutBounds().getWidth() * 2.2;
        this.h = auxText.getLayoutBounds().getHeight();

        this.defaultColor = defaultColor; this.hoverColor = hoverColor;
        this.labelText = labelText; this.clickReturn = clickReturn;
        this.buttonType = ButtonType.LabelButton;
    }

    public void draw(GraphicsContext gc){
        if(buttonType == ButtonType.LabelButton){
            if(isMouseOver()){
                gc.setFill(this.hoverColor);
            }else{
                gc.setFill(this.defaultColor);
            }

            gc.setTextAlign(TextAlignment.LEFT);
            gc.fillText(labelText, x, y + h);
        }
    }

    protected boolean isMouseOver(){
        Point mousePos = Helper.mousePosInWindow();
        if(mousePos.getX() > this.x && mousePos.getX() < this.x + this.w &&
            mousePos.getY() > this.y && mousePos.getY() < this.y + this.h){
            return true;
        }else{
            return false;
        }
    }

    public String getClickString(){
        return this.clickReturn;
    }

    public boolean isClicked(){
        if(isMouseOver() && Input.getMouseClick()){
            return true;
        }else{
            return false;
        }
    }
}
